let db = require("../db/index");

// 楼宇管理列表查询
exports.building = (req, res) => {
    var sql =
        `select * from buildingmanagement order by date asc`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};
// 楼宇管理列表条件查询
exports.buildingselect = (req, res) => {
    var sql =
        `select * from buildingmanagement where Belongingcommunity="${req.query.name}"`;
    db.query(sql, [], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err.message);
        }
        res.send(data);
    });
};

// 楼宇管理列表数据删除
exports.buildingdel = (req, res) => {
    var sql = `delete from buildingmanagement where date = ${req.query.date}`;
    db.query(sql, [req.body.id], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err);
        }
        res.send(data);
    });
};
// 添加楼宇
exports.buildingadd = (req, res) => {
    var sql = `insert into buildingmanagement(Belongingcommunity,Buildingname,Numberofunits,Buildingtype,buildingstructure,Numberoflayers,BuildingUsage,Constructiondate,acceptancedate,buildingarea,usablearea,edit,del,opertes,Buildingnumber,Totalnumberofhouses,Housenumberingrules,isstorageroom,note)values('${req.query.Belongingcommunity}','${req.query.Buildingname}','${req.query.Numberofunits}','${req.query.Buildingtype}','${req.query.buildingstructure}','${req.query.Numberoflayers}','${req.query.BuildingUsage}','${req.query.Constructiondate}','${req.query.acceptancedate}','${req.query.buildingarea}','${req.query.usablearea}','房屋管理','编辑','删除','${req.query.Buildingnumber}','${req.query.Totalnumberofhouses}','${req.query.Housenumberingrules}','${req.query.isstorageroom}','${req.query.note}')`;
    db.query(sql, [req.body.id], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err);
        }
        res.send({
            data,
            state:200
        });
    });
};
// 修改楼宇
exports.buildingchange = (req, res) => {
    var sql = `update buildingmanagement set Belongingcommunity='${req.query.Belongingcommunity}',Buildingname='${req.query.Buildingname}',Numberofunits='${req.query.Numberofunits}',Buildingtype='${req.query.Buildingtype}',buildingstructure='${req.query.buildingstructure}',Numberoflayers='${req.query.Numberoflayers}',BuildingUsage='${req.query.BuildingUsage}',Constructiondate='${req.query.Constructiondate}',acceptancedate='${req.query.acceptancedate}',buildingarea='${req.query.buildingarea}',usablearea='${req.query.usablearea}',Buildingnumber='${req.query.Buildingnumber}',Totalnumberofhouses='${req.query.Totalnumberofhouses}',Housenumberingrules=${req.query.Housenumberingrules},isstorageroom=${req.query.isstorageroom},note='${req.query.note}' where date=${req.query.date} `;
    db.query(sql, [req.body.id], (err, data) => {
        if (err) {
            console.log("出错了", err);
            return res.send("错误" + err);
        }
        res.send({
            data,
            state:200
        });
    });
};